﻿Imports GdiGaming

Public Class GenericCharacter
    Inherits GameObject

    Private Shared _Random As New Random

    Private _GotLazy As Date
    Private _IsLazy As Boolean
    Private _WasClicked As Boolean

    Protected Overrides Sub OnCollision(ByVal e As GdiGaming.CollisionEventArgs)
        MyBase.OnCollision(e)
        e.CollisionObject.Position = Vector2.GetVectorToward(e.CollisionObject.Position, Position, -6)
    End Sub

    Protected Overrides Sub OnInput(ByVal e As GameEngineEventArgs)
        MyBase.OnInput(e)
        If Not _IsLazy Then
            If e.Engine.Input.IsKeyDown(Keys.D) Then
                Position += New Vector2(3, 0)
            End If
            If e.Engine.Input.IsKeyDown(Keys.A) Then
                Position += New Vector2(-3, 0)
            End If
            If e.Engine.Input.IsKeyDown(Keys.W) Then
                Position += New Vector2(0, -3)
            End If
            If e.Engine.Input.IsKeyDown(Keys.S) Then
                Position += New Vector2(0, 3)
            End If
        End If
    End Sub

    Protected Overrides Sub OnMouseDown(ByVal e As GdiGaming.GameEngineEventArgs)
        MyBase.OnMouseDown(e)
        _WasClicked = True
    End Sub

    Protected Overrides Sub OnMouseUp(ByVal e As GdiGaming.GameEngineEventArgs)
        MyBase.OnMouseUp(e)
        _WasClicked = False
        e.Engine.Audio.Play("chimes", False)
    End Sub

    Protected Overrides Sub OnUpdate(ByVal e As GdiGaming.GameEngineEventArgs)
        MyBase.OnUpdate(e)
        If IsCollider Then
            If _WasClicked Then
                Position = e.Engine.Input.CurrentMouseState.MouseLocation
            Else
                If _IsLazy Then
                    If Date.Now.Subtract(_GotLazy).TotalSeconds > 1 Then
                        _IsLazy = False
                    End If
                Else
                    If GenericCharacter._Random.Next(1, 101) > 99 Then
                        _GotLazy = Date.Now
                        _IsLazy = True
                    End If
                End If
            End If
        End If
        If Not HasCollision Then
            _RotationAngle += 5.01F
            If _RotationAngle >= Geometry.FULL_CIRCLE Then
                _RotationAngle -= Geometry.FULL_CIRCLE
            End If
        End If
    End Sub
End Class